<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="会员名称" prop="uname">
        <el-input
          v-model="queryParams.uname"
          placeholder="请输入会员名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现账号" prop="accountNumber">
        <el-input
          v-model="queryParams.accountNumber"
          placeholder="请输入提现账号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="申请日期">
      <el-date-picker
        v-model="dateRange"
        style="width: 240px"
        value-format="yyyy-MM-dd"
        type="daterange"
        range-separator="-"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      ></el-date-picker>
      </el-form-item>

      <el-form-item label="提现方式" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择提现方式" @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in dict.type.pay_type"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="审核状态" prop="audiStatus">
        <el-select v-model="queryParams.audiStatus" placeholder="请选择审核状态" @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in dict.type.audi_status"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['video:DWthdrawalRecord:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['video:DWthdrawalRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="DWthdrawalRecordList" >
      <el-table-column label="会员名称" align="center" prop="uname" />
      <el-table-column label="提现方式" align="center" prop="typeName" />
      <el-table-column label="提现账号" align="center" prop="accountNumber" />
      <el-table-column label="当前佣金金额" align="center" prop="currentAmount" />
      <el-table-column label="提现金额" align="center" prop="amount" />
      <el-table-column label="审核状态" align="center" prop="audiStatusName" />
      <el-table-column label="审核账号" align="center" prop="updateBy" />
      <el-table-column label="申请时间" align="center" prop="createTime" />
      <el-table-column label="审核时间" align="center" prop="updateTime" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">

        <template slot-scope="scope">
          <el-button
            v-if="scope.row.audiStatus == '1'"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['video:DWthdrawalRecord:edit']"
          >审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改提现记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-input type="hidden" v-model="form.uid"  />
        <el-form-item label="会员名称" prop="uname">
          <el-input v-model="form.uname" disabled />
        </el-form-item>
        <el-form-item label="提现方式" prop="type">
          <el-select v-model="form.type" placeholder="请选择提现方式" disabled>
            <el-option
              v-for="item in dict.type.pay_type"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="提现账号" prop="accountNumber">
          <el-input v-model="form.accountNumber" placeholder="请输入提现账号" disabled />
        </el-form-item>

        <el-form-item label="提现金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入提现金额" disabled />
        </el-form-item>

        <el-form-item label="审核状态" prop="audiStatus">
          <el-radio-group v-model="form.audiStatus">
            <el-radio
              v-for="dict in dict.type.audi_status"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="审核备注" prop="remarks">
          <el-input  v-model="form.remarks" placeholder="请输入审核备注" />
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDWthdrawalRecord, getDWthdrawalRecord, delDWthdrawalRecord, addDWthdrawalRecord, updateDWthdrawalRecord } from "@/api/video/DWthdrawalRecord";

export default {
  name: "DWthdrawalRecord",
  dicts: ['audi_status','pay_type'],

  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 提现记录表格数据
      DWthdrawalRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        uname: null,
        accountNumber: null,
        type: null,
        audiStatus: null,
        beginTime: null,
        endTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      dateRange: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询提现记录列表 */
    getList() {
      this.loading = true;
      if(this.dateRange.length>0){
        this.queryParams.beginTime=this.dateRange[0];
        this.queryParams.endTime=this.dateRange[1];
      }else{
        this.queryParams.beginTime=null;
        this.queryParams.endTime=null;
      }
      listDWthdrawalRecord(this.queryParams).then(response => {
        this.DWthdrawalRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        uid: null,
        uname:null,
        type: null,
        accountNumber: null,
        currentAmount: null,
        amount: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange= [];
      this.queryParams.beginTime=null;
      this.queryParams.endTime=null;
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加提现记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      console.log(row.uname);

      getDWthdrawalRecord(id).then(response => {
        this.form = response.data;
        this.form.uname=row.uname;
        this.open = true;
        this.title = "提现审核";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDWthdrawalRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDWthdrawalRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('video/DWthdrawalRecord/export', {
        ...this.queryParams
      }, `DWthdrawalRecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
